#include <bits/stdc++.h>
using namespace std;
int t,n,m,l,v,cnt;
struct cc{
	int d,v,a;
	bool p;
};
bool cmp(cc x,cc y){
	return x.d < y.d;
}
struct oo{
	int d;
	vector <int> c;
};
bool cmp1(oo x,oo y){
	return x.c.size()<y.c.size();
}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	scanf("%d",&t);
	for (int i=1;i<=t;i++){
		cnt=0;
		scanf("%d%d%d%d",&n,&m,&l,&v);
		//vector <int> cp[n];//store the id of tester that can detect the car
		int cp[n][m];
		memset(cp,0,sizeof(cp));
		int u[n];
		memset(u,0,sizeof(u));
		cc car[n];
		for (int j = 1 ; j <= n ; j ++){
			scanf("%d%d%d",&car[j].d,&car[j].v,&car[j].a);
		}
		sort(car+1,car+1+n,cmp);
		oo p[m];
		for (int j = 1;j <= m;j ++){
			scanf("%d",&p[j].d);
			int k=n;
			while(car[k].d > p[j].d) k--;//better needed
			for (int i = 1 ; i <= k;i++) cp[u[i]]=j,u[i]++;//cp[i].push_back(j);
		}
		for (int i=1;i<=n;i++){
			int v0=car[i].v;
			int a=car[i].a;
			int ni=cp[i].size()-1;
			double s=(v*v-v0*v0)/(2*a);
			double ll=double(l-car[i].d);
			if(a == 0){
				if(v0 > v) cnt++;
			}
			else{
				if((a>0&& v0 > v)||(a<0 && s>ll && v0>v)){
					cnt++;
					car[i].p=true;
					for (int j=0;j<ni;i++){
						p[cp[i][j]].c.push_back(i);
					}
				}
				else if((a<0 && v0<v)||(a>0 && v0<v && s>ll)){
					continue;
				}
				else{
					for (int j=0;j<ni;j++){
						int id=cp[i][j];
						double lll=double(p[id].d-l);
						if(a>0&&lll<s){
							p[id].c.push_back(i);
							if(!car[i].p) car[i].p=true,cnt++;
						}
						if(a<0&&lll>s){
							p[id].c.push_back(i);
							if(!car[i].p) car[i].p=true,cnt++;
						}
					}
				}
			}
		}	
		printf("%d",cnt);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
